/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <QColor>
#include <QColorDialog>
#include <QPainter>
#include "colorwidget.h"
#include "log.h"

ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent),
	m_foreground(QColor(0, 0, 0))
{
}

ColorWidget::~ColorWidget()
{
}

void ColorWidget::paintEvent(QPaintEvent* event)
{
	QPainter p(this);
	QBrush b(m_foreground);
	p.setBrush(b);
	QRect r(1, 1, 0, 0);
	if(size().width() > 40)
	{
		r.setX(size().width() / 2 - 20);
		r.setWidth(40);
	}
	else
		r.setWidth(size().width());

	if(size().height() > 40)
	{
		r.setY(size().height() / 2 - 20);
		r.setHeight(40);
	}
	else
		r.setHeight(size().height());

	p.drawRect(r);
}

QColor ColorWidget::foreground()
{
	return m_foreground;
}

QColor ColorWidget::background()
{
	return m_background;
}

void ColorWidget::mouseDoubleClickEvent(QMouseEvent* event)
{
	QColor newcolor = QColorDialog::getColor(m_foreground);
	if(newcolor.isValid())
		m_foreground = newcolor;
	update();
	emit foregroundColor(newcolor);
}

